package lumis.portal.audit;

import lumis.portal.PortalException;
import lumis.portal.PortalObjectNotFoundException;
import lumis.portal.dao.hibernate.GenericHibernateDao;
import lumis.portal.transaction.PortalTransactionFactory;

/**
 * Data access object for {@link AuditEntryType}.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
class AuditEntryTypeDao extends GenericHibernateDao<AuditEntryType, String>
{
	protected AuditEntryTypeDao()
	{
		super(AuditEntryType.class);
	}
	
	/**
	 * Returns the audit entry type with the given key.
	 * @param categoryKey	the audit entry type's key.
	 * @return the audit entry type.
	 * @throws PortalObjectNotFoundException if the audit entry type was not found.
	 * @since 6.0.0
	 */
	protected AuditEntryType findByKey(String typeKey) throws PortalException
	{
		AuditEntryType entryType = (AuditEntryType) getSession(PortalTransactionFactory.getCurrentTransaction())
														.getNamedQuery(AuditEntryType.NAMED_QUERY_FIND_BY_KEY)
														.setParameter("key", typeKey).uniqueResult();
		if (entryType == null)
		{
			throw new PortalObjectNotFoundException("AuditEntryType with key '" + typeKey + "' not found");
		}
		
		return entryType;
	}
}